package com.das.metrocloud.ssoserver;

import org.springframework.boot.autoconfigure.*;
import org.mybatis.spring.annotation.*;
import org.springframework.cloud.netflix.eureka.*;
import org.springframework.boot.*;
import com.das.framework.common.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.*;
import org.springframework.context.annotation.*;
import org.springframework.cloud.client.loadbalancer.*;
import java.util.*;
import java.security.*;

@SpringBootApplication
@RestController
@MapperScan({ "com.das.cloud.system.dao" })
@ComponentScan({ "com.das.cloud.system.service", "com.das.framework.web.spring", "com.das.metrocloud.ssoserver" })
@EnableEurekaClient
public class AuthApplication
{
    public static void main(final String[] args) {
        SpringApplication.run((Class)AuthApplication.class, args);
    }
    
    @IgnoreUserToken
    @RequestMapping({ "/" })
    public String index() {
        return "OSC Auth server....";
    }
    
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }
    
    @RequestMapping({ "/api/test" })
    public byte[] test() throws NoSuchAlgorithmException {
        final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
        final SecureRandom secureRandom = new SecureRandom("ABCD".getBytes());
        keyPairGenerator.initialize(1024, secureRandom);
        final KeyPair keyPair = keyPairGenerator.genKeyPair();
        final PublicKey pk = keyPair.getPublic();
        System.out.println(keyPair.getPublic().getFormat());
        final byte[] publicKeyBytes = keyPair.getPublic().getEncoded();
        final byte[] privateKeyBytes = keyPair.getPrivate().getEncoded();
        final Map<String, byte[]> map = new HashMap<String, byte[]>();
        map.put("pub", publicKeyBytes);
        map.put("pri", privateKeyBytes);
        return publicKeyBytes;
    }
}
